package com.sky.mapper.admin;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.enumeration.OperationType;
import com.sky.pojo.Dish;
import com.sky.pojo.Setmeal;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SetmealMapper {
    /**
     * 根据分类id查询套餐
     */
    @Select("select * from setmeal where category_id = #{categoryId};")
    List<Setmeal> queryByCategoryId(Long categoryId);

    /**
     * 根据分类id查询套餐的数量
     */
    @Select("select count(id) from setmeal where category_id = #{categoryId}")
    Integer countByCategoryId(Long id);

    /**
     * 分页查询
     */
    Page<SetmealVO> pageQuery(SetmealPageQueryDTO setmealPageQueryDTO);

    /**
     * 根据菜品id查询
     */
    @Select("select * from setmeal_dish where dish_id = #{id}")
    List<Dish> queryByDishId(Long id);

    /**
     * 插入数据
     */
    @Options(useGeneratedKeys = true, keyColumn = "id", keyProperty = "id")
    @Insert("insert into setmeal (name,category_id,price,status,description,image,make_time,create_time,create_user,update_time,update_user)" +
            "values(#{name},#{categoryId},#{price},#{status},#{description},#{image},#{makeTime},#{createTime},#{createUser},#{updateTime},#{updateUser})")
    @AutoFill(OperationType.INSERT)
    void insert(Setmeal setmeal);

    /**
     * 查询套餐状态
     */
    List<Setmeal> queryStatusByIds(List<Long> ids);

    /**
     * 删除。批量删除
     */
    void delete(List<Long> ids);

    /**
     * 根据id查询
     */
    @Select("select * from setmeal where id = #{id}")
    SetmealVO queryById(Integer id);

    /**
     * 更新
     */
    @AutoFill(OperationType.UPDATE)
    void update(Setmeal setmeal);
}
